import time
from concurrent.futures import ThreadPoolExecutor
import requests
import uuid
from fake_useragent import UserAgent

BASE_URL = "http://192.168.1.204:8008/task/"


def create_time():
    return time.strftime('&Y%M%d')


def create_uid():
    return str(uuid.uuid4())


def add_task(task_name, task_desc, task_time):
    headers = {'User-Agent': UserAgent().random}
    data = {
        'task_name': task_name,
        'task_desc': task_desc,
        'task_time': task_time,
    }
    # r = requests.post(BASE_URL, headers=headers, data=data, proxies={'http': 'http://192.168.1.204:8008/'})
    r = requests.post(BASE_URL, headers=headers, data=data)
    print(r.json())


if __name__ == '__main__':
    with ThreadPoolExecutor(10) as pool:
        for i in range(20):
            # pool.submit(add_task, f"task-{i}", f"task-{i}", create_time(), create_uid())
            pool.submit(add_task, task_name=f"task-{i}", task_desc=f"task-{i}", task_time=create_time())
